﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace Sharpimeter.Model
{
    public class Config
    {
        private string MacAddr;
        private string Pincode;
        private string DBAddr;
        private string DBUsr;
        private string DBPwd;
        private string DBDatabase;
        private string PatientID;

        public Config() { ReadValues(); }

        public void ReadValues()
        {
            XmlTextReader reader = new XmlTextReader("config.xml");

            if (File.Exists("config.xml")) 
            { 
                reader.ReadToFollowing("MacAddress");
                MacAddr = reader.ReadElementContentAsString();
                reader.ReadToFollowing("Pincode");
                Pincode = reader.ReadElementContentAsString();
                reader.ReadToFollowing("DatabaseAddress");
                DBAddr = reader.ReadElementContentAsString();
                reader.ReadToFollowing("DatabaseUser");
                DBUsr = reader.ReadElementContentAsString();
                reader.ReadToFollowing("DatabaseName");
                DBDatabase = reader.ReadElementContentAsString();
                reader.ReadToFollowing("DatabasePassword");
                DBPwd = reader.ReadElementContentAsString();
                reader.ReadToFollowing("PatientID");
                PatientID = reader.ReadElementContentAsString();

                reader.Close();
            }
        }

        public string GetMacAddress() { return MacAddr; }
        public string GetPincode() { return Pincode; }
        public string GetDatabaseAddress() { return DBAddr; }
        public string GetDatabaseUsername() { return DBUsr; }
        public string GetDatabasePassword() { return DBPwd; }
        public string GetDatabaseName() { return DBDatabase; }
        public string GetPatientID() { return PatientID; }
    }
}
